<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>测试ref</h2>
      <p id="count"></p>
      <p id="user"></p>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.global.js"></script>
    <script>
      const { effect, ref } = Vue

      const count = ref(1)
      const user = ref({
        name: 'Jack',
        age: 12
      })

      effect(() => {
        console.log('count effect')
       document.getElementById('count').innerHTML = count.value
      })

      effect(() => {
        console.log('user effect')
        document.getElementById('user').innerHTML = user.value.name + '---' + user.value.age
      })

      setTimeout(() => {
        // count.value = 2

        // user.value = {
        //   name: 'Tom',
        //   age: 14
        // }

        user.value.name = 'BOB'
      }, 2000);
    </script>
  </body>
</html>
